
* {
  padding: 0;
  background-clip: padding-box;
  -gtk-secondary-caret-color: $primary;
}

//
// Base States
//
.background {
  background-color: $background;
  color: $text;
}

dnd {
  color: $text;
}

.normal-icons {
  -gtk-icon-size: 16px;
}

.large-icons {
  -gtk-icon-size: 32px;
}

spinner:disabled,
arrow:disabled,
scrollbar:disabled,
check:disabled,
radio:disabled,
treeview.expander:disabled { -gtk-icon-filter: opacity(0.5); }

%view, .view {
  background-color: $base;
  color: $text;

  &:disabled {
    // background-color: $base_alt;
    color: $text-disabled;
  }

  &:selected { @extend %selected_items; }
}

textview {
  > text {
    @extend %view;

    > selection { @extend %selected_items; }
  }

  &:drop(active) {
    caret-color: $warning;
  }
}

textview > border {
  background-color: $base_alt;
  color: $text-disabled;
}

iconview {
  @extend %view;
  &:hover, &:active, &:selected { border-radius: $button_radius; }

  &:drop(active) {
    box-shadow: none;
  }

  > dndtarget:drop(active) {
    border: none;
  }
}

rubberband {
  border: 1px solid $primary;
  background-color: gtkalpha($primary, 0.3);
}

flowbox {
  > rubberband { @extend rubberband; }

  > flowboxchild {
    padding: 4px;
    border-radius: 2px;

    &:selected { @extend %selected_items; }
  }
}

gridview {
  > rubberband { @extend rubberband; }

  > child {
    padding: 3px;

    &:selected {
      @extend %selected_items;
    }

    box { //cells
      border-spacing: 8px; //label separation
      margin: 12px;
    }
  }
}

coverflow cover {
  color: $text;
  background-color: $base;
  border: none;
}

label {
  caret-color: currentColor; // this shouldn't be needed.

  &.separator {
    @extend .dim-label;

    color: $text;
  }

  row:selected &,
  &:selected {
    color: on($primary);

    &:disabled { color: on($primary, disabled); }
  }

  > selection {
    background-color: $primary;
    color: on($primary);
  }

  &:disabled {
    color: $text-disabled;

    > selection { color: on($primary, disabled); }

    tab &,
    button & { color: inherit; }
  }
}

.dim-label { opacity: 0.45; }

window.assistant {
  .sidebar {
    padding: 4px 0;
    // background-color: $base;
    // border-top: 1px solid $border;
  }

  &.csd .sidebar { border-top-style: none; }

  .sidebar > label {
    min-height: $medium_size;
    padding: 0 12px;
    color: $text-disabled;
    font-weight: 500;

    &.highlight { color: $text; }
  }
}

window.aboutdialog image.large-icons {
  -gtk-icon-size: 128px;
}

%osd, .osd {
  color: on($osd);
  border: none;
  background-color: $osd;
  background-clip: padding-box;
  border-radius: $button_radius * 1.5;
  padding: $space_size;
  margin: $space_size;
  box-shadow: $shadow_4;
}

//
// Spinner Animation
//
@keyframes spin {
  to { transform: rotate(1turn); }
}

spinner {
  background: none;
  opacity: 0; // non spinning spinner makes no sense
  -gtk-icon-source: -gtk-icontheme('process-working-symbolic');

  &:checked {
    opacity: 1;
    animation: spin 1s linear infinite;

    &:disabled { opacity: 0.3; }
  }
}

//
// General Typography
//

.large-title {
   font-weight: 300;
   font-size: 24pt;
}
.title-1 {
   font-weight: 800;
   font-size: 20pt;
}
.title-2 {
   font-weight: 800;
   font-size: 15pt;
}
.title-3 {
   font-weight: 700;
   font-size: 15pt;
}
.title-4 {
   font-weight: 700;
   font-size: 13pt;
}
.heading {
   font-weight: 700;
   font-size: 11pt;
}
.body {
   font-weight: 400;
   font-size: 11pt;
}
.caption-heading {
   font-weight: 700;
   font-size: 9pt;
}
.caption {
   font-weight: 400;
   font-size: 9pt;
}

//
// Entries
//
%flat_entry {
  @include entry(flat-normal);
  border-radius: 0;
  &:focus-within { @include entry(flat-focus); }
  &:drop(active) { @include entry(flat-hover); }
  &:disabled { @include entry(flat-disabled); }
}

%entry_fallback {
  &, &.flat {
    @include entry(fallback-normal);
    &:focus-within { @include entry(fallback-focus); }
    &:disabled { @include entry(fallback-disabled); }
  }
}

%entry_native {
  .background & {
    @include entry(normal);
    &:focus-within { @include entry(focus); }
    &:disabled { @include entry(disabled); }
  }

  .background &.flat { @extend %flat_entry; }
}

entry {
  min-height: $medium_size;
  padding: 0 8px;

  // fallback entries for non-native apps
  @extend %entry_fallback;

  // standard entries for native Gtk+ apps
  @extend %entry_native;

  // standard linked-entries for native Gtk+ apps
  .background .linked > &,
  .background .linked.vertical > &,
  .background .linked > &.flat,
  .background .linked.vertical > &.flat {
    @extend %flat_entry;
  }

  > image { // icons inside the entry
    color: gtkalpha(currentColor, 0.9);

    &:hover, &:active { color: currentColor; }

    &:disabled { color: gtkalpha(currentColor, 0.45); }

     &.left {
      margin-left: ($medium_size - 16px) / 2 - 8px;
      margin-right: $space_size;
    }

    &.right {
      margin-left: $space_size;
      margin-right: ($medium_size - 16px) / 2 - 8px;
    }
  }

  &:focus-within {
    > placeholder { opacity: 0; }
  }

  > text > placeholder {
    @extend .dim-label;
  }

  > text > block-cursor {
    color: $base;
    background-color: $text;
  }

  undershoot {
    &.left { @include undershoot(left); }

    &.right { @include undershoot(right); }
  }

  > text > selection { @extend %selected_items; }

  // entry error and warning style
  @each $e_type, $e_color in (error, $error),
                             (warning, $warning) {
    .background &.#{$e_type}, .background &.search.#{$e_type} {
      @include entry(normal, $e_color);

      &:focus-within { @include entry(focus, $e_color); }

      &:disabled { @include entry(disabled, $e_color); }

      &.flat {
        @include entry(flat-normal, $e_color);

        &:focus-within { @include entry(flat-focus, $e_color); }

        &:disabled { @include entry(flat-disabled, $e_color); }
      }
    }
  }

  &.password image.caps-lock-indicator {
    color: $text-secondary-disabled;
  }

  &:drop(active) {
    &:focus-within, & {
      border-color: $warning;
      box-shadow: inset 0 0 0 1px $warning;
    }
  }

  .osd & {
    @include entry(osd);

    &:focus-within { @include entry(osd-focus); }
    &:disabled { @include entry(osd-insensitive); }
  }

  > progress {
    margin: 2px (2px - 8px);
  }

  progress > trough > progress {
    background-color: transparent;
    background-image: none;
    border-radius: 0;
    border-style: none none solid;
    border-width: 2px;
    border-color: $primary;
    box-shadow: none;
  }

  .linked:not(.vertical) > &,  // linked entries
  .linked.vertical > &,  // Vertically linked entries
  .linked:not(.vertical) > &.flat,
  .linked.vertical > &.flat { border-radius: 0; }
}

treeview entry {
  &.flat, & {
    min-height: 0;
    padding: 2px;
    border-radius: 0;
    background-color: $base;

    &, &:focus-within {
      border-image: none;
      box-shadow: none;
    }
  }
}


// Editable Labels
editablelabel > stack > text {
  @include entry(normal);
}

//
// Buttons
//
// stuff for .needs-attention
$_dot_color: if($variant=='light', $primary, lighten($primary, 15%));
@keyframes needs_attention {
  from { background-image: radial-gradient(farthest-side, $_dot_color 0%, transparentize($_dot_color, 1) 0%); }
  to { background-image: radial-gradient(farthest-side, $_dot_color 95%, transparentize($_dot_color, 1)); }
}

%flat_button {
  @include button(flat-normal);
  &:hover { @include button(flat-hover); }
  &:focus { @include button(flat-focus); }
  &:active { @include button(flat-active); }
  &:disabled { @include button(flat-disabled); }
  &:checked { @include button(flat-checked); }
  &:checked:disabled { @include button(flat-checked-disabled); }
}

%simple_flat_button {
  @include button(flat-normal);
  &:hover { @include button(flat-hover); }
  &:focus { @include button(flat-focus); }
  &:active { @include button(flat-active); }
  &:disabled { @include button(flat-disabled); }
}

%combo_flat {
  border-radius: 0;
  background: none;
  font-weight: normal;

  @include entry(flat-normal);

  &:hover {
    @include entry(flat-hover);
  }

  &:checked {
    @include entry(flat-focus);
  }

  &:disabled {
    @include entry(flat-disabled);
  }
}

button {
  min-height: 24px;
  min-width: 16px;
  padding: $space_size $space_size * 1.5;
  border-radius: $button_radius;
  font-weight: 500;

  // fallback buttons for non-native apps
  @include button(fallback-normal);
  &:hover { @include button(fallback-hover); }
  &:active, &:checked { @include button(fallback-active); }
  &:disabled { @include button(fallback-disabled); }
  &:checked:disabled { @include button(fallback-checked-disabled); }

  // raised buttons for native Gtk+ apps
  .background & {
    @include button(normal);
    &:hover { @include button(hover); }
    &:focus { @include button(focus); }
    &:active { @include button(active); }
    &:disabled { @include button(disabled); }
    &:checked { @include button(checked); }
    &:checked:disabled { @include button(checked-disabled); }
  }

  &.flat {
    @include button(flat-normal);
    &:hover { @include button(flat-hover); }
    &:active { @include button(flat-active); }
    &:disabled { @include button(flat-disabled); }
    &:checked { @include button(flat-checked); }
    &:checked:disabled { @include button(flat-checked-disabled); }
  }

  &.text-button {
    padding-left: 16px;
    padding-right: 16px;
  }

  &.image-button {
    min-width: 24px;
    padding: ($medium_size - 24px) / 2;
    border-radius: $button_radius;
  }

  &.text-button.image-button {
    border-radius: $button_radius;

    label {
      &:first-child {
        margin-left: 16px - ($medium_size - 24px) / 2;
        margin-right: 2px;
      }

      &:last-child {
        margin-left: 2px;
        margin-right: 16px - ($medium_size - 24px) / 2;
      }

      &:only-child {
        margin-left: 16px - ($medium_size - 24px) / 2;
        margin-right: 16px - ($medium_size - 24px) / 2;
      }
    }

    image:not(:only-child) {
      &:first-child { margin-left: (24px - 16px) / 2; }

      &:last-child { margin-right: (24px - 16px) / 2; }
    }
  }

  &.close,
  &.round-button,
  &.circular { // The Bloody Circul Button
    @extend %circular_button;
  }

  .linked > & {
    @extend %linked;
  }

  .linked.vertical > & {
    @extend %linked_vertical;
  }

  .linked > &.flat,
  .linked.vertical > &.flat {
    border-radius: $button_radius;

    &.image-button {
      border-radius: $button_radius;
    }

    &.text-button.image-button {
      border-radius: $button_radius;
    }
  }

  .background &.combo,
  .background .linked > &.combo,
  .background .linked entry + &,
  .background .linked entry + & + & { @extend %combo_flat; }

  .background .linked.stack-switcher > & {
    @extend %flat_button;
    border-radius: 0;

    &:checked {
      box-shadow: inset 0 -2px $primary;
      background-color: transparent;
    }
  }

  .background buttonbox.linked > & {
    border-radius: $button_radius;
  }

  row:selected & {
    &:disabled { color: on($primary, secondary-disabled); }
    &.flat {
      color: on($primary, secondary);

      &:hover, &:active, &:checked {
        background-color: $track;
        color: on($primary);
      }

      &:disabled { color: on($primary, secondary-disabled); }

      &:checked:disabled {
        background-color: rgba(white, 0.12);
        color: on($primary, disabled);
      }
    }
  }

  // big standalone buttons like in Documents pager
  &.osd {
    padding: ($large_size - 24px) / 2 ($large_size - 16px) / 2;

    &.image-button { padding: ($large_size - 24px) / 2; }

    &:disabled { opacity: 0; }
  }

  //overlay / OSD style
  @at-root %osd_button,
  .osd & {
    background-color: rgba(white, 0.05);

    &.flat { background-color: transparent; }

    &, &.flat {
      color: on($primary, secondary);
      box-shadow: none;

      &:hover { background-color: rgba(white, 0.1); }
      &:active { background-color: rgba(white, 0.2); }
      &:checked { background-color: rgba(white, 0.15); }
      &:disabled {
        background-color: rgba(white, 0.02);
        color: on($primary, secondary-disabled);
      }

      &:hover, &:active, &:checked, &:focus {
        color: on($primary);
        box-shadow: none;
      }
    }
  }

  // Suggested and Destructive Action buttons
  @each $b_type, $b_color in (suggested-action, $suggested),
                             (destructive-action, $destructive) {
    &.#{$b_type} {
      background-color: $b_color;
      color: on($primary);
      box-shadow: $shadow_1;

      &:hover {
        @include button(hover, $b_color, on($primary));
        background-color: lighten($b_color, 5%);
        color: on($primary);
      }

      &:disabled { @include button(disabled, $b_color, on($primary)); }

      &:checked { background-color: mix(on($primary), $b_color, percentage(0.3)); }

      &.flat {
        background-color: transparent;
        color: $b_color;
        @include button(flat-normal, $b_color, on($primary));

        &:hover { @include button(flat-hover, $b_color, on($primary)); }
        &:active, &:checked { @include button(flat-active, $b_color, on($primary)); }
        &:disabled { @include button(flat-disabled, $b_color, on($primary)); }
      }
    }
  }

  stackswitcher > & {
    // to position the needs attention dot, padding is added to the button
    // child, a label needs just lateral padding while an icon needs vertical
    // padding added too.

    outline-offset: -4px; // needs to be set or it gets overriden by GtkRadioButton outline-offset

    > label {
      padding-left: $space_size;  // label padding
      padding-right: $space_size; //
    }

    > image {
      padding-left: $space_size;   // image padding
      padding-right: $space_size;  //
      padding-top: 3px;    //
      padding-bottom: 3px; //
    }

    &.text-button {
      // compensate text-button paddings
      padding-left: $space_size + 4px;
      padding-right: $space_size + 4px;
    }

    &.image-button {
      // we want image buttons to have a 1:1 aspect ratio, so compensation
      // of the padding added to the GtkImage is needed
      padding-left: ($medium_size - 16px) / 2 - 6px;
      padding-right: ($medium_size - 16px) / 2 - 6px;
    }

    &.needs-attention {
      > label,
      > image { @extend %needs_attention; }

      &:checked {
        > label,
        > image {
          animation: none;
          background-image: none;
        }
      }
    }
  }

  // hide separators
  separator {
    min-width: 0;
    min-height: 0;
    background: none;
  }

  // make the row image-button be circular
  row &.image-button {
    border-radius: $circular_radius;
  }
}

toolbutton {
  button {
    &, &.image-button, &.toggle {
      @extend %flat_button; // Use flat button for all toolbuttons
    }
  }
}

%needs_attention {
  animation: needs_attention $shorter_duration $deceleration_curve forwards;
  background-repeat: no-repeat;
  background-position: right 3px;
  background-size: 6px 6px;

  &:dir(rtl) { background-position: left 3px; }
}

%linked_middle {
  border-radius: 0;
}

%linked {
  @extend %linked_middle;

  &:first-child {
    border-top-left-radius: $button_radius;
    border-bottom-left-radius: $button_radius;
  }

  &:last-child {
    border-top-right-radius: $button_radius;
    border-bottom-right-radius: $button_radius;
  }

  &:only-child {
    border-radius: $button_radius;
  }
}

%linked_vertical_middle {
  border-radius: 0;
}

%linked_vertical{
  @extend %linked_vertical_middle;

  &:first-child {
    border-top-left-radius: $button_radius;
    border-top-right-radius: $button_radius;
  }

  &:last-child {
    border-bottom-left-radius: $button_radius;
    border-bottom-right-radius: $button_radius;
  }

  &:only-child {
    border-radius: $button_radius;
  }
}

/* menu buttons */
modelbutton.flat {
  min-height: $item_size;
  padding: 0 $space_size * 1.5;
  border-radius: $button_radius;
  color: inherit;
  @extend %simple_flat_button;

  &:selected { @extend %selected_items; }

  check,
  radio {
    &:not(:checked):not(:indeterminate) { color: gtkalpha(currentColor, 0.45); }

    &, &:hover { background-image: none; }

    &:active { animation: none; }

    &:last-child { margin-left: -8px; margin-right: -16px; }

    &:first-child { margin-left: -16px; margin-right: -8px; }
  }
}

modelbutton.flat arrow {
  background: none;
  transition: none;

  &:hover { background: none; }

  &.left { -gtk-icon-source: -gtk-icontheme("go-previous-symbolic"); }

  &.right { -gtk-icon-source: -gtk-icontheme("go-next-symbolic"); }
}

// oldstyle toolbar buttons
.toolbar button {
  margin: 1px;
  @extend %flat_button;
}

button.color {
  min-height: $small_size;
  min-width: $small_size;
  padding: $space_size;

  > colorswatch:only-child {
    &, > overlay { border-radius: 0; }
  }
}

%list_button,
list > row button.image-button:not(.flat) {
  @extend %flat_button;

  @each $b_type, $b_color in (suggested-action, $primary),
                         (destructive-action, $destructive) {
    &.#{$b_type} { // allow colored buttons in lists #3643
      @include button(normal, $c:$b_color, $tc:white);
    }
  }
}

//
// Links
//
%link,
link {
  &, &:hover, &:active { color: $link; }

  &:visited {
    &, &:hover, &:active {
      color: $link-visited;
      *:selected & { color: mix(white, $link-visited, 60%); }
    }
  }

  &:disabled { color: rgba($link, 0.45); }

  @at-root %link_selected,
  &:selected,
  *:selected & { color: on($primary); }
}

button.link {
  @extend %link;

  &:hover {
    color: $link;
    box-shadow: inset 0 0 0 9999px rgba($link, 0.15);
  }

  > label { text-decoration-line: underline; }
}

//
// GtkSpinButton
//
spinbutton {
  > text {
    > selection { @extend %selected_items; }
    > block-cursor {
      background-color: $text;
      color: $base;
    }
  }

  &:not(.vertical) {
    padding: 0;
    // in this horizontal configuration, the whole spinbutton
    // behaves as the entry, so we extend the entry styling
    // and nuke the style on the internal entry
    @extend %entry_fallback;

    .background &,
    .background &.flat {
      @extend %flat_entry;
      transition: $longer_transition;
      border-radius: 0;

      &, &:focus-within, &:disabled {
        > text {
          &, &:focus-within, &:disabled {
            box-shadow: none;
            background: none;
            border-image: none;
            transition: none;
          }
        }
      }
    }

    > text {
      &, &:focus-within, &:disabled {
        min-width: $large_size - 8px * 2;
        padding: 2px $space_size * 1.5;
        // reset all the other props since the spinbutton node is styled here
        margin: 0;
        border: none;
        border-radius: 0;
        box-shadow: none;
        background-color: transparent;
      }
    }

    > button {
      // margin: $space_size;
      @extend %simple_flat_button;

      &, &:hover, &:active, &:checked, &:disabled {
        @extend %small_button;
        border: solid 6px transparent;
      }

      &.up:dir(ltr),
      &.down:dir(rtl) { margin-left: -3px; }

      &.up:dir(rtl),
      &.down:dir(ltr) { margin-right: -3px; }
    }

    .linked > & > button.up,
    .linked > & > button.down { // Reset
      @extend %flat_button;

      &, &:hover, &:active, &:checked, &:disabled {
        @extend %small_button;
        border: solid 6px transparent;
      }
    }
  }

  // Vertical
  &.vertical {
    // in the vertical configuration, we treat the spinbutton
    // as a box, and tweak the style of the entry in the middle
    // so that it's linked

    // FIXME: this should not be set at all, but otherwise it gets the wrong
    // color
    &:disabled { color: $text-disabled; }

    &:drop(active) {
      box-shadow: none;
    }

    > text {
      min-height: $medium_size;
      min-width: $large_size;
      padding: 0;
      @extend %entry_fallback;
    }

    > button {
      min-height: $medium_size;
      min-width: $large_size;
      padding: 0;

      &.up { border-radius: 2px 2px 0 0; }
      &.down { border-radius: 0 0 2px 2px; }
    }
  }

  // Misc
  treeview &:not(.vertical) {
    min-height: 0;
    border-style: none;
    border-radius: 0;

    > text {
      min-height: 0;
      padding: 1px 2px;
    }
  }

  font-feature-settings: "tnum";
}

//
// ComboBoxes
//
dropdown > popover.menu.background > contents { padding: 0; } //allow search entries with no margin
dropdown > button > box { border-spacing: $space_size; }

dropdown,
combobox {
  arrow {
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
    min-height: 16px;
    min-width: 16px;
  }

  // align menu labels with the button label
  > popover.menu > contents modelbutton {
    padding-left: $space_size * 1.5;
    padding-right: $space_size * 1.5;
  }

  .background & { // unset all properties in combobox node
    border: unset;
    border-image: unset;
    border-radius: unset;
    background-color: unset;
    color: unset;
    box-shadow: unset;
  }

  // fallback combo-entries for non-native apps
  entry.combo {
    border-radius: 2px;
    margin-right: -32px;
    padding-right: 32px;
    @include entry(fallback-normal);
    &:focus { @include entry(fallback-focus); }
    &:disabled { @include entry(fallback-disabled); }
  }

  > .linked:not(.vertical) > button:not(:only-child).combo {
    border: none;
    border-image: none;
    box-shadow: none;
    min-height: 16px;
    min-width: 16px;
    margin: 4px;
    padding: $space_size;
    @extend %flat_button;
    @extend %circular_button;
  }

  // standard combo-entries for native Gtk+ apps
  .background & entry.combo {
    @include entry(flat-normal);
    &:focus { @include entry(flat-focus); }
    &:disabled { @include entry(flat-disabled); }
  }

  decoration { transition: none; } // workaround for menuitem selection

  button.combo cellview {
    &:dir(ltr) { margin-left: 8px - ($medium_size - 16px) / 2; }
    &:dir(rtl) { margin-right: 8px - ($medium_size - 16px) / 2; }
  }

  &.linked {
    button:nth-child(2) {
      &:dir(ltr) {
        border-top-right-radius: $button_radius;
        border-bottom-right-radius: $button_radius;
      }
      &:dir(rtl) {
        border-top-left-radius: $button_radius;
        border-bottom-left-radius: $button_radius;
      }
    }
  }

  &:drop(active) { // FIXME: untested
    box-shadow: none;
  }

  // newstyle
  popover {
   margin-top: $space_size;
   padding: 0;

   listview {
     margin: $space_size 0;

     & > row {
       padding: $space_size;

       &:selected {
         @extend %selected_items;
       }
     }
   }

    // drodowns with searchboxes on top
    .dropdown-searchbar {
      padding: $space_size;
      border-bottom: 1px solid $border;
    }
  }
}

// workaround for LibreOffice with fallback-mode liked-buttons
@each $order, $edge in (first-child, right),
                       (last-child, left) {
  .linked:not(combobox) > button.combo:#{$order} {
    border-#{$edge}-width: 0;
    &:only-child { border-width: 1px; }
  }
}

//
// Toolbars
//
.toolbar,
toolbar {
  padding: $space_size / 2;
  background-color: $background;

  button { @extend %flat_button; }

  // on OSD
  .osd & { background-color: transparent; }

  // stand-alone OSD toolbars
  &.osd {
    padding: $space_size;
    border-radius: 2px;
    box-shadow: $shadow_2, inset 0 1px $highlight;
    background-color: $base;

    &:backdrop { box-shadow: $shadow_1, inset 0 1px $highlight; }

    &.left,
    &.right,
    &.top,
    &.bottom { border-radius: 0; } // positional classes for `attached` osd toolbars
  }

  // toolbar separators
  &.horizontal separator { margin: $space_size / 2; }
  &.vertical separator { margin: $space_size / 2; }

  &:not(.inline-toolbar):not(.osd) {
    scale,
    entry,
    spinbutton,
    button { margin: $space_size / 2; }

    .linked entry,
    .linked spinbutton,
    .linked button {
      &:not(:first-child) { margin-left: 0; }
      &:not(:last-child) { margin-right: 0; }
    }

    switch { margin: ($space_size / 2 + $space_size) ($space_size / 2); }
  }
}

searchbar > revealer > box {
  border-spacing: $space_size;
  padding: $space_size;
  border-style: solid;
  border-width: 0 0 1px;
  border-color: $border;
  background-color: $background;
  background-clip: border-box;
}

//
// Header bars
//

%header_button {
  @include button(header-normal);
  &:hover { @include button(header-hover); }
  &:active { @include button(header-active); }
  &:disabled { @include button(header-disabled); }
  &:checked { @include button(header-checked); }
  // &:checked:hover { @include button(header-checked-hover); }
  &:checked:disabled, &:checked:backdrop { @include button(header-checked-disabled); }
  &:backdrop {
    color: on($header, disabled);
    &:disabled { color: on($header, secondary-disabled); }
  }
}

%headerbar_flat_button {
  border-radius: 0;

  &:hover {
    border-radius: 0;
    color: indicator(header);
    box-shadow: inset 0 -2px gtkalpha(indicator(header), 0.5);
    &, &:disabled { background-color: transparent; }
  }

  &:checked, &:active {
    box-shadow: inset 0 -2px indicator(header);
    background: none;
    color: indicator(header);
    border-radius: 0;

    &:disabled, &:backdrop {
      background: none;
      color: gtkalpha(indicator(header), 0.35);
      box-shadow: inset 0 -2px gtkalpha(indicator(header), 0.35);
    }
  }

  &:checked:hover { background: none; }

  &:disabled { background: none; }
}

headerbar {
  transition: background-color $shorter_duration $deceleration_curve,
              color $shorter_duration $deceleration_curve;
  min-height: $medium_size;
  padding: 0 $space_size * 2;
  box-shadow: $header_shadow;
  background-color: $header;
  color: on($header);

  &:backdrop {
    color: on($header, disabled);
    &:disabled { color: on($header, secondary-disabled); }
  }

  &:disabled { color: on($header, disabled); }

  .title {
    padding: 0 12px;
    font-weight: bold;
  }

  .subtitle {
    padding: 0 12px;
    font-size: smaller;

    @extend .dim-label;
  }

  button:not(.suggested-action):not(.destructive-action) { @extend %header_button; }

  button.suggested-action, button.destructive-action {
    &:disabled {
      color: gtkalpha(currentColor, 0.3);
      > label { color: inherit; }
    }
  }

  &.selection-mode {
    transition: $shorter_transition;
    box-shadow: $shadow_1, inset 0 1px $highlight;
    background-color: $primary;
    color: on($primary);

    &:backdrop {
      color: on($primary, secondary);
    }

    .subtitle:link { color: on($primary); }

    button:not(.suggested-action):not(.destructive-action) {
      color: currentColor;

      &:disabled {
        color: gtkalpha(currentColor, 0.3);

        > label { color: inherit; }
      }

      &:hover {
        box-shadow: inset 0 -2px on(dark, secondary);
        color: on(dark, secondary);

        &, &:disabled { background: none; }
      }

      &:checked {
        box-shadow: inset 0 -2px currentColor;
        color: currentColor;

        &:hover { background-color: transparent; color: currentColor; }

        &:disabled {
          color: gtkalpha(currentColor, 0.3);

          > label { color: inherit; }
        }
      }
    }

    .selection-menu {
      padding-left: 16px;
      padding-right: 16px;

      .arrow { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
    }
  }

  .fullscreen &,
  .tiled &,
  .maximized & {
    border-radius: 0; // squared corners when the window is fullscreen, maximized or tiled
    box-shadow: $header_shadow;
  }

  &.default-decoration {
    min-height: $small_size;
    padding: 2px $space_size;

    .tiled &,
    .maximized &,
    .fullscreen & { box-shadow: none; }

    windowcontrols {
      button {
        transition: $shorter_duration;
        background-size: 16px 16px;

        &:hover, &:active {
          background-size: 22px 22px;
        }
      }

      button, menubutton {
        min-height: 26px;
        min-width: 26px;
        margin: 0;
        padding: 0;
      }

      menubutton button {
        min-height: 20px;
        min-width: 20px;
        margin: 0;
        padding: 4px;
      }
    }
  }

  &.default-decoration,
  .csd &.default-decoration,
  &.default-decoration:backdrop,
  .csd &.default-decoration:backdrop {  // needed under wayland, since all gtk3 windows are csd windows
    box-shadow: inset 0 1px $highlight;
  }

  .solid-csd & {
    &:dir(rtl), &:dir(ltr) { // specificity bump
      margin: 0;
      border-radius: 0;
      box-shadow: $header_shadow;
    }
  }

  separator.titlebutton { @extend %header_separator; }

  // Reset buttons and entris
  .linked > button,
  .linked > entry,
  .background & .linked entry + button,
  .background & .linked entry + button + button {
    &, &:hover, &:active, &:checked, &:disabled {
      border-radius: $button_radius;
    }
  }

  // special case for stack-switchers
  windowhandle stackswitcher.linked {
    > button:not(.suggested-action):not(.destructive-action) { @extend %headerbar_flat_button; }
  }

  > windowhandle > box {
    &,
    > box.start,
    > box.end {
      border-spacing: $space_size;
    }
  }

  &.windowhandle {
    viewswitcher button:not(.titlebutton):not(.suggested-action):not(.destructive-action) {
      margin-top: 0;
      margin-bottom: 0;
      @extend %headerbar_flat_button;
    }
  }

  entry,
  spinbutton,
  separator:not(.sidebar),
  button,
  menubutton {
    margin-top: $space_size;
    margin-bottom: $space_size;
  }

  // Reset margins for buttons inside menubutton
  menubutton > button {
    margin-top: 0px;
    margin-bottom: 0px;
  }

  button:not(.suggested-action):not(.destructive-action) { @extend %header_button; }

  switch {
    margin-top: ($large_size - 22px) / 2;
    margin-bottom: ($large_size - 22px) / 2;

    @if $theme == 'black' and $topbar =='dark' {
      background-color: rgba(on($header), 0.3);

      &:disabled { color: rgba(on($header), 0.3); }

      &:checked {
        background-color: rgba(on($header), 0.5);

        &:disabled { background-color: rgba(on($header), 0.5 * 0.3); }
      }

      &:checked slider { background-color: on($header); }
    }
  }

  // reset button margins of the spinbutton
  spinbutton button {
    margin-top: 0;
    margin-bottom: 0;
  }

  separator { @extend %header_separator; }

  &.titlebar {
    box-shadow: $header_shadow, inset 0 1px $highlight;

    headerbar:not(.titlebar) {
      background: none;
      box-shadow: none;
    }

    .tiled &,
    .maximized &,
    .fullscreen & { box-shadow: $header_shadow; }
  }

  .titlebar > & {
    box-shadow: $header_shadow, inset 0 1px $highlight;
  }

  separator:first-child + &, // tackles the paned container case
  &:first-child { border-top-left-radius: $button_radius; }
  &:last-child { border-top-right-radius: $button_radius; }

  stack & { // tackles the stacked headerbars case
    &:first-child, &:last-child {
      border-top-left-radius: $button_radius;
      border-top-right-radius: $button_radius;
      border: none;
    }
  }

  window.tiled &,
  window.tiled-top &,
  window.tiled-right &,
  window.tiled-bottom &,
  window.tiled-left &,
  window.maximized &,
  window.fullscreen &,
  window.solid-csd & {
    &,
    &:first-child,
    &:last-child,
    &:only-child {
      border-top-left-radius: 0;
      border-top-right-radius: 0;
    }
  }
}

.titlebar {
  &, &.background {
    border-top-left-radius: $button_radius;
    border-top-right-radius: $button_radius;
  }

  .background.tiled &,
  .background.tiled-top &,
  .background.tiled-right &,
  .background.tiled-bottom &,
  .background.tiled-left &,
  .background.maximized &,
  .background.solid-csd & {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
  }

  &.solid-csd headerbar {
    box-shadow: $header_shadow;
  }

  .solid-csd > &.vertical {
    box-shadow: none;

    headerbar.titlebar {
      box-shadow: none;
    }

    searchbar {
      background: none;
    }
  }
}

.titlebar:not(headerbar) {
  box-shadow: $header_shadow, inset 0 1px $highlight;
  border: none;

  .tiled &,
  .maximized &,
  .fullscreen & { box-shadow: $header_shadow; }

  > separator { // separator between titlebars
    min-width: 1px;
    min-height: 1px;
    background-color: $header;
    background-image: image($header);
    border: none;
  }

  window.csd > & {
    padding: 0;
    background: none;
    border: none;
    box-shadow: none;
  }
}

window.background > box.vertical > headerbar:not(.titlebar) { // reset headerbar style for not CSD window
  &, &:backdrop { background-color: $header; }
  border-radius: 0 0 0 0;
  box-shadow: none;

  // Fixes split headerbars
  separator:first-child + &,
  &:first-child {
    &, &:backdrop {
      border-top-left-radius: 0;
    }
  }

  &:last-child {
    &, &:backdrop {
      border-top-right-radius: 0;
    }
  }
}

%header_separator {
  min-width: 0;
  min-height: 0;
  background-color: $header;
  border: none;
}

%headerbar_entry {
  background-color: rgba(on($header), 0.06);
  color: on($header);
  caret-color: on($header);
  border-image: none;
  box-shadow: none;

  &:focus-within {
    background-color: rgba(on($header), 0.09);
    border-image: none;
    box-shadow: none;
  }

  &:disabled {
    background-color: rgba(on($header), 0.03);
    color: on($header, disabled);
    border-image: none;
    box-shadow: none;
  }
}

.titlebar, headerbar {
  .background &:not(.horizontal) entry {
    @extend %headerbar_entry;
  }
}

// Development versions of apps to use a differently styled headerbar

window.devel {
  headerbar.titlebar {
    $c: darken($background, 10%);
    $gradient: cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
               linear-gradient(to right, transparent 65%, transparentize($primary, 0.8)),
               linear-gradient(to top, darken($c, 3%), $c 3px, lighten($c, 6%));
    @if $variant == 'dark' {
      $gradient: cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
                 linear-gradient(to right, transparent 65%, transparentize($primary, 0.9)),
                 linear-gradient(to top, lighten($c, 3%) 3px, lighten($c, 5%));
    }

    background: $background $gradient;

    &:backdrop {
      background: $background cross-fade(10% -gtk-icontheme("system-run-symbolic"), image(transparent)) 90% 0/256px 256px no-repeat,
                  image($background); /* background-color would flash */
    }
  }
}

//
// Pathbars
//
%pathbar_button,
.background pathbar > button {
  @extend %flat_button;
  border-radius: 2px;
  padding-left: ($medium_size - 24px) / 2;
  padding-right: ($medium_size - 24px) / 2;

  &:checked {
    box-shadow: inset 0 -2px $primary;

    &, &:disabled { background-color: transparent; }
  }

  &.text-button, &.image-button, & {
    padding-left: 4px;
    padding-right: 4px;
  }

  &.text-button.image-button label {
    padding-left: 0;
    padding-right: 0;
  }

  &.text-button.image-button, & {
    label:last-child { padding-right: 8px; }
    label:first-child { padding-left: 8px; }
  }

  image {
    padding-left: 4px;
    padding-right: 4px;
  }

  &.slider-button {
    padding-left: 0;
    padding-right: 0;
  }
}

//
// Tree Views
//
columnview.view,
treeview.view {
  border-left-color: $solid-border;  // this is actually the tree lines color,
  border-top-color: $solid-border; // while this is the grid lines color, better then nothing

  > rubberband { @extend rubberband; } // to avoid borders being overridden by the previously set props

  &:hover, &:active, &:selected { border-radius: 0; }

  &.separator {
    min-height: 1px + 2px * 2;
    color: $border;
  }

  &:drop(active) {
    box-shadow: none;
  }

  > dndtarget:drop(active) {
    border-style: solid none;
    border-width: 1px;
    border-color: $accent;

    &.after { border-top-style: none; }
    &.before { border-bottom-style: none; }
  }


  &.expander {
    -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');

    &:dir(rtl) { -gtk-icon-transform: rotate(90deg); }

    color: $text-secondary;

    &:hover, &:active { color: $text; }
    &:disabled { color: $text-secondary-disabled; }

    &:selected {
      color: on($primary, secondary);

      &:hover, &:active { color: on($primary); }
      &:disabled { color: on($primary, secondary-disabled); }
    }
  }

  &.progressbar { // progress bar in treeviews
    border-style: none none solid;
    border-width: $bar_size;
    border-color: $primary;
    box-shadow: none;
    background-color: transparent;
    border-radius: 0;

    &:selected { border-color: currentColor; }
  }

  &.trough { // progress bar trough in treeviews
    border-style: none none solid;
    border-width: $bar_size;
    border-color: gtkalpha($primary, 0.3);
    box-shadow: none;
    background-color: transparent;
    border-radius: 0;

    &:selected { border-color: $track; }
  }

  > header {
    > button {
      @extend %row_activatable;

      padding: 2px $space_size;
      border-style: none solid solid none;
      border-width: 1px;
      border-color: $border;
      border-radius: 0;
      background-clip: border-box;

      &, &:hover, &:active { box-shadow: none; }

      &, &:disabled { background-color: $base; }

      &:last-child { border-right-style: none; }
    }
  }

  button.dnd,
  header.button.dnd { // for treeview-like derive widgets
    padding: 2px $space_size;
    border-style: none solid solid;
    border-width: 1px;
    border-color: $border;
    border-radius: 0;
    box-shadow: none;
    background-color: $base;
    background-clip: border-box;
    color: $primary;
  }

  acceleditor > label { background-color: $primary; } // see tests/testaccel to test
}

//
// Menus
//
menubar {
  padding: 0;
  color: on($header, secondary);
  background-color: $header;
  transition: none;

  &:backdrop {
    color: transparentize(on($header, secondary), 0.35);
  }

  > item {
    min-height: $item_size;
    padding: 0 ($space_size * 2);
    color: on($header, secondary);
    transition: none;

    &:hover { //Seems like it :hover even with keyboard focus
      transition: none;
      background-color: $primary;
      color: on(dark);
    }

    &:disabled { color: on($header, disabled); }
  }

  & > item popover.menu.background > contents {
    padding: $space_size;
  }
  //nested submenus
  & > item popover.menu popover.menu {
    padding: 0 0 4px 0;
  }
  & > item popover.menu.background popover.menu.background > contents {
    margin: 0;
    border-radius: $button_radius; //including top
  }
}

popover.menu {
  padding: 0;

  & > arrow,
  &.background > contents {
    padding: $space_size;
    box-shadow: inset 0 1px $highlight, $shadow_4;
    background-color: $base;
    border: none;
    border-radius: $button_radius;
  }

  &.background separator {
    margin: $space_size 0;
  }

  box.inline-buttons {
    padding: 0 $space_size;

    button.image-button.model {
      min-height: $item_size;
      min-width: $item_size;
      padding: 0;
      border: none;
      outline: none;
      @extend %flat_button;
    }
  }

  box.circular-buttons {
    button.circular.image-button.model {
      @extend %flat_button;
      padding: $space_size;
      min-height: $item_size;
      min-width: $item_size;
    }
  }

  accelerator {
    color: gtkalpha(currentColor, 0.55);

    &:dir(ltr) { margin-left: $space_size * 2; }
    &:dir(rtl) { margin-right: $space_size * 2; }
  }

  arrow.left,
  radio.left,
  check.left {
    margin-left: -2px;
    margin-right: $space_size;
  }

  arrow.right,
  radio.right,
  check.right {
    margin-left: $space_size;
    margin-right: -2px;
  }

  modelbutton {
    min-height: $item_size;
    min-width: $item_size * 1.5;
    padding: 0 $space_size * 2;
    border-radius: $button_radius;

    &:selected {
      color: $text;
      background-color: rgba($text, 0.06);
    }

    &:selected:active {
      color: $text;
      background-color: rgba($text, 0.12);
    }
  }

  label.title {
    font-weight: bold;
    padding: 4px 32px; //this will fall apart with font sizing
  }
}

//
// Popovers
//
%flat_theme_button {
  box-shadow: none;
  background-color: transparent;
  transition: $shorter_transition;

  &:hover {
    background-color: $divider;
    color: $text;
  }

  &:active {
    @include button(header-active);
  }

  &:checked {
    @include button(header-checked);
  }

  &:disabled {
    background-color: transparent;
    color: $text-disabled;
  }

  &:checked:disabled {
    background-color: rgba($primary, 0.5);
    color: rgba(on($primary), 0.5);
  }
}

popover.background {
  background-color: transparent;
  font: initial; // Decouple the font of popovers from their entry/textview

  > arrow,
  > contents {
    transition: $shadow_transition;
    padding: 0;
    box-shadow: $shadow_4;
    background-color: $suface;
    border: none;
  }

  &:backdrop {
    background-color: transparent;

    > arrow,
    > contents {
      box-shadow: $shadow_2;
    }
  }

  > contents {
    padding: $space_size;
    border-radius: $button_radius;

    > list,
    > .view,
    > toolbar {
      border-style: none;
      background-color: transparent;
      box-shadow: none;
    }

    separator {
      background-color: $solid-border;
      margin: $space_size / 2;
    }

    list separator { margin: 0; }
  }

  .osd &,
  &.touch-selection,
  &.magnifier {
    background-color: transparent;

    > arrow,
    > contents {
      @extend %osd;
      margin: 0;
      border: none;
      box-shadow: none;

      button:not(.suggested-action):not(.destructive-action) { @extend %osd_button; }
    }
  }

  entry { @extend %flat_entry; }

  .linked button:not(.combo) { border-radius: $button_radius; margin: 0 2px; }

  button:not(.suggested-action):not(.destructive-action) {
    @extend %flat_theme_button;
  }

  &.menu button,
  button.model {
    margin: 0;
    min-height: $item_size;
    padding: 0 $space_size;
    box-shadow: none;
  }

  &.touch-selection,
  &.magnifier {
    button { @extend %osd_button; }
  }
}

magnifier {
  background-color: $base;
}

//
// Notebooks
//
notebook {
  > header {
    border-width: 1px;
    border-color: $border;
    background-color: $background;
    background-clip: border-box;

    &.top {
      border-bottom-style: solid;
      > tabs {
        margin-bottom: -1px;
        > tab {

          &:hover { box-shadow: inset 0 -2px gtkalpha($indicator, 0.3); }

          &:checked { box-shadow: inset 0 -2px $indicator; }
        }
      }
    }

    &.bottom {
      border-top-style: solid;
      > tabs {
        margin-top: -1px;
        > tab {

          &:hover { box-shadow: inset 0 2px gtkalpha($indicator, 0.3); }

          &:checked { box-shadow: inset 0 2px $indicator; }
        }
      }
    }

    &.left {
      border-right-style: solid;
      > tabs {
        margin-right: -1px;
        > tab {

          &:hover { box-shadow: inset -2px 0 gtkalpha($indicator, 0.3); }

          &:checked { box-shadow: inset -2px 0 $indicator; }
        }
      }
    }

    &.right {
      border-left-style: solid;
      > tabs {
        margin-left: -1px;
        > tab {

          &:hover { box-shadow: inset 2px 0 gtkalpha($indicator, 0.3); }

          &:checked { box-shadow: inset 2px 0 $indicator; }
        }
      }
    }

    &.top > tabs > arrow {
      @extend %notebook_vert_arrows;

      border-top-style: none;
    }

    &.bottom > tabs > arrow {
      @extend %notebook_vert_arrows;

      border-bottom-style: none;
    }

    @at-root %notebook_vert_arrows {
      padding-left: 4px;
      padding-right: 4px;

      &.down {
        margin-left: -8px;
        -gtk-icon-source: -gtk-icontheme('pan-start-symbolic');
      }

      &.up {
        margin-right: -8px;
        -gtk-icon-source: -gtk-icontheme('pan-end-symbolic');
      }
    }

    &.left > tabs > arrow {
      @extend %notebook_horz_arrows;

      border-left-style: none;
    }

    &.right > tabs > arrow {
      @extend %notebook_horz_arrows;

      border-right-style: none;
    }

    @at-root %notebook_horz_arrows {
      padding-top: 4px;
      padding-bottom: 4px;

      &.down {
        margin-top: -8px;
        -gtk-icon-source: -gtk-icontheme('pan-up-symbolic');
      }

      &.up {
        margin-bottom: -8px;
        -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');
      }
    }

    > tabs > arrow {
      @extend %simple_flat_button;

      min-height: 16px;
      min-width: 16px;
      border-radius: 0;
    }

    tab {
      transition: $shorter_transition;
      min-height: $small_size;
      min-width: $small_size;
      padding: $space_size $space_size * 2;

      outline-offset: -6px;

      border-width: 1px;         // for reorderable tabs
      border-color: transparent; //
      color: $text-secondary;
      font-weight: 500;

      &:hover {
        color: $text;

        &.reorderable-page {
          border-color: $border;
          background-color: $base_alt;
        }
      }

      &:disabled { color: $text-secondary-disabled; }

      &:checked {
        transition: $shorter_transition;
        color: $text;

        &:disabled { color: $text-disabled; }

        &.reorderable-page {
          border-color: $border;
          background-color: $base;
        }
      }

      // close button
      // colors the button like the label, overridden otherwise
      button.flat {
           min-height: 24px;
           min-width: 24px;
           padding: 0;
           border-radius: $circular_radius;
      }
    }

    &.top,
    &.bottom {
      tabs {
        padding-left: 8px;
        padding-right: 8px;

        &:not(:only-child) {
          &:first-child { margin-left: 0; }
          &:last-child { margin-right: 0; }
        }

        tab {
          &.reorderable-page {
            margin: 0 -1px;
            border-style: none solid;
          }
        }
      }
    }

    &.left,
    &.right {
      tabs {
        padding-top: 8px;
        padding-bottom: 8px;

        &:not(:only-child) {
          &:first-child { margin-top: 0; }
          &:last-child { margin-bottom: 0; }
        }

        tab {
          &.reorderable-page {
            margin: -1px 0;
            border-style: solid none;
          }
        }
      }
    }
  }

  > stack:not(:only-child) { // the :not(:only-child) is for "hidden" notebooks
    background-color: $base;

    entry,
    spinbutton:not(.vertical) { @extend %flat_entry; }
  }
}

//
// Scrollbars
//
scrollbar {
  $_slider_min_length: 24px;

  transition: $shorter_transition;
  background-color: $base;
  background-clip: $extra_background_clip;

  // scrollbar border
  &.top { border-bottom: 1px solid $border; }
  &.bottom { border-top: 1px solid $border; }
  &.left { border-right: 1px solid $border; }
  &.right { border-left: 1px solid $border; }

  // slider
  > range > trough > slider {
    transition: $shorter_transition, margin 0, border-width 0;
    min-width: 5px;
    min-height: 5px;
    border: 3px solid transparent;
    border-radius: 100px;
    background-clip: padding-box;
    background-color: $text-disabled;

    &:hover { background-color: $text-disabled; }
    &:active { background-color: $text-secondary; }
    &:disabled { background-color: $text-secondary-disabled; }
  }

  > range.fine-tune {
    > trough > slider {
      transition: $shorter_transition, margin 0, border-width 0, min-width 0, min-height 0;
      min-width: 4px;
      min-height: 4px;
    }

    &.horizontal > trough > slider { margin: 2px 0; }
    &.vertical > trough > slider { margin: 0 2px; }
  }

  &.overlay-indicator {
    &:not(.dragging):not(.hovering) {
      border-color: transparent;
      background-color: transparent;

      > range > trough > slider {
        min-width: 4px;
        min-height: 4px;
        margin: 4px - 1px;
        border: 1px solid gtkalpha($base, 0.3);
      }

      button {
        min-width: 4px;
        min-height: 4px;
        margin: 4px - 1px;
        border: 1px solid gtkalpha($base, 0.3);
        border-radius: $circular_radius;
        background-color: $text-disabled;
        background-clip: padding-box;
        -gtk-icon-source: none;

        &:disabled { background-color: $text-secondary-disabled; }
      }

      &.horizontal {
        > range > trough > slider { min-width: $_slider_min_length; }
        button { min-width: 8px; }
      }

      &.vertical {
        > range > trough > slider { min-height: $_slider_min_length; }
        button { min-height: 8px; }
      }
    }

    &.dragging,
    &.hovering { background-color: gtkalpha($base, 0.9); }
  }

  &.horizontal > range > trough > slider { min-width: $_slider_min_length; }
  &.vertical > range > trough > slider { min-height: $_slider_min_length; }

  // button styling
  button {
    @extend %simple_flat_button;

    min-width: 16px;
    min-height: 16px;
    padding: 0;
    border-radius: 0;
  }

  // button icons
  &.vertical {
    button {
      &.down { -gtk-icon-source: -gtk-icontheme('pan-down-symbolic'); }
      &.up { -gtk-icon-source: -gtk-icontheme('pan-up-symbolic'); }
    }
  }

  &.horizontal {
    button {
      &.down { -gtk-icon-source: -gtk-icontheme('pan-end-symbolic'); }
      &.up { -gtk-icon-source: -gtk-icontheme('pan-start-symbolic'); }
    }
  }
}

//
// Switch
//
$switch_shadow_size: ($space_size * 2 - 2px);

switch {
  transition: all $shorter_duration $deceleration_curve;
  margin: $space_size 0;
  padding: 0 2px;
  border: 5px solid transparent;
  border-radius: $circular_radius;
  background-color: rgba($text, 0.25);
  background-clip: padding-box;
  font-size: 0;

  &:disabled { opacity: 0.5; }

  &:checked { background-color: rgba($accent, 0.5); }

  // hide on/off icons for >=3.24.5
  > image {
    color: transparent;
  }

  > slider {
    transition: all $shorter_duration $deceleration_curve;
    min-width: 20px;
    min-height: 20px;
    margin: -$space_size / 2;
    border-radius: $circular_radius;
    box-shadow: 0 0 0 $switch_shadow_size transparent, $shadow_1;
    background-color: $suface;
    color: $suface;
  }

  &:hover > slider { color: $text; box-shadow: 0 0 0 $switch_shadow_size rgba($text, 0.1), $shadow_1; }
  &:focus > slider { color: $accent; box-shadow: $shadow_1; }
  &:focus:hover > slider { color: $accent; box-shadow: 0 0 0 $switch_shadow_size rgba($accent, 0.1), $shadow_1; }
  &:checked > slider { background-color: $accent; color: $accent; }
  &:checked:hover > slider { color: $accent; box-shadow: 0 0 0 $switch_shadow_size rgba($accent, 0.1), $shadow_1; }

  row:selected & {
    background-color: rgba(on(dark), 0.2);

    &:checked {
      background-color: rgba(on($primary), 0.6);
    }

    > slider {
      background-color: lighten($accent, 25%);
    }

    &:checked > slider {
      animation: none;
      background-color: on($primary);
    }
  }
}


//
// Check and Radio items
//
// draw regular check and radio items using our PNG assets
// all assets are rendered from assets.svg. never add pngs directly

//selection-mode
.view.content-view.check:not(list),
.content-view .tile check:not(list) {
  min-height: 40px;
  min-width: 40px;
  margin: 0;
  padding: 0;
  box-shadow: none;
  background-color: transparent;
  background-image: none;

  @each $s, $as in ('', '-unchecked'),
                   (':checked', '-checked') {
    &#{$s} {
      -gtk-icon-source: -gtk-scaled(url("assets/selectionmode-checkbox#{$as}#{$asset-suffix}.png"),
                                    url("assets/selectionmode-checkbox#{$as}#{$asset-suffix}@2.png"));
    }
  }
}

checkbutton,
radiobutton {
  outline: none;
  border-spacing: 4px;
  border-radius: 2px;
}

checkbutton.text-button,
radiobutton.text-button {
  // this is for a nice focus on check and radios text
  padding: 2px;
  outline-offset: 0;

  label:not(:only-child) { margin: 0 4px; }
}

%check_radio_button,
checkbutton > check:not(:checked):not(:indeterminate),
radiobutton > radio:not(:checked):not(:indeterminate) {
  color: $text-secondary;
  &:hover, &:active { color: $text; }
  &:disabled { color: $text-secondary-disabled; }
}

%row_selected_check,
checkbutton check,
radiobutton radio {
  row:selected &,
  treeview.view:selected &,
  row.activatable:selected & {
    &, &:focus {
      &, &:active, &:checked, &:indeterminate {
        color: on($primary, secondary);
        background: none;
        box-shadow: none;
        &:disabled { color: on($primary, secondary-disabled); }
      }

      &:hover {
        color: on($primary);
        background: none;
        box-shadow: none;
        &:disabled { color: on($primary, disabled); }
      }
    }
  }
}

check,
radio {
  min-height: 24px;
  min-width: 24px;
  margin: -$space_size;
  padding: $space_size;
  @extend %simple_flat_button;
  @extend %circular_button;
  @extend %row_selected_check;

  &:checked, &:indeterminate {
    color: indicator(accent);

    &:hover { box-shadow: inset 0 0 0 9999px gtkalpha(indicator(accent), 0.15); }

    &:disabled {  color: gtkalpha(indicator(accent), 0.3); }
  }

  &:not(:hover):focus { box-shadow: inset 0 0 0 9999px transparent; }

  popover modelbutton.flat & {
    &, &:focus, &:hover, &:focus:hover, &:active, &:disabled {
      transition: none; // FIXME: this is a workaround for a popover check/radio long transition issue
      box-shadow: none;
      background-image: none;
    }

    &:not(:checked):not(:indeterminate):not(:disabled) { color: $text-secondary; }

    &.left:dir(rtl) {
      margin-left: -16px;
      margin-right: -8px;
    }

    &.right:dir(ltr) {
      margin-left: -8px;
      margin-right: -16px;
    }
  }

  popover.menu modelbutton & {
    transition: none;
    margin: 0; // this is a workaround for a menu check/radio size allocation issue
    padding: 0;
    color: on($menu, secondary);

    &:dir(ltr) { margin-right: 8px; }
    &:dir(rtl) { margin-left: 8px; }

    &:checked, &:indeterminate {
      color: indicator(accent);
      &:disabled {  color: gtkalpha(indicator(accent), 0.3); }
    }
  }
}

%check,
check {
  -gtk-icon-source: -gtk-scaled(url("assets/scalable/checkbox-unchecked-symbolic#{$asset-suffix}.svg"),
                                url("assets/scalable/checkbox-unchecked-symbolic#{$asset-suffix}@2.svg"));

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/checkbox-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/checkbox-mixed-symbolic.svg")); }
}

%radio,
radio {
  -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-unchecked-symbolic.svg"));

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-mixed-symbolic.svg")); }
}

%small_check,
popover.menu modelbutton check {
  & {
    min-height: 16px;
    min-width: 16px;
    border-radius: 2px;
    -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-checkbox-unchecked-symbolic.svg"));
  }

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-checkbox-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-checkbox-mixed-symbolic.svg")); }
}

%small_radio,
popover.menu modelbutton radio {
  & {
    min-height: 16px;
    min-width: 16px;
    border-image: none;
    -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-radio-unchecked-symbolic.svg"));
  }

  &:checked { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-radio-checked-symbolic.svg")); }

  &:indeterminate { -gtk-icon-source: -gtk-recolor(url("assets/scalable/small-radio-mixed-symbolic.svg")); }
}

treeview.view check,
treeview.view radio {
  padding: 0;

  &:hover {
    box-shadow: none;
    background-image: none;
    background-color: transparent;

    &:disabled { box-shadow: none; }
    &:selected { box-shadow: none; }
  }

  & {
    color: $text-secondary;
    &:hover, &:active { color: $text; }
    &:disabled { color: $text-secondary-disabled; }
    &:checked, &:indeterminate { color: indicator(accent); }
    &:checked:disabled, &:indeterminate:disabled { color: gtkalpha(indicator(accent), 0.3); }
  }

}

treeview.view radio:checked {
  -gtk-icon-source: -gtk-recolor(url("assets/scalable/radio-checked-symbolic.svg"));
  border-image: none;
}

//
// GtkScale
//
scale {
  // sizing
  $_marks_lenght: 8px;
  $_marks_distance: 7px;

  $slider_size: 32px;
  $marks_slider_size: 38px;

  $trough_size: 2px;

  $slider_margin: -($slider_size - $trough_size) / 2;
  $marks_slider_margin: -($marks_slider_size - $trough_size) - $slider_margin;

  $color_slider_margin: -($slider_size) / 2;
  $color_marks_slider_margin: -($marks_slider_size - 16px) - $color_slider_margin;

  min-height: $medium_size - $slider_size;
  min-width: $medium_size - $slider_size;
  padding: ($slider_size / 2);

  // the backing bit
  > trough {
    transition: all $shorter_duration $deceleration_curve;
    outline: none;
    background-color: $track;

    &:disabled { background-color: $track-disabled; }

    > slider {
      min-height: $slider_size;
      min-width: $slider_size;
      margin: $slider_margin;
    }
  }

  // the colored part of the backing bit
  > trough > highlight {
    transition: all $shorter_duration $deceleration_curve;
    background-color: $accent;

    &:disabled { background-color: transparent; }
  }

  // this is another differently styled part of the backing bit, the most relevant use case is for example
  // in media player to indicate how much video stream as been cached
  > trough > fill {
    transition: all $shorter_duration $deceleration_curve;
    background-color: $track;

    &:disabled { background-color: transparent; }
  }

  > trough > slider {
    transition: all $shorter_duration $deceleration_curve;
    border-radius: 100%;
    color: transparent;
    background-repeat: no-repeat;
    background-position: center;

    @each $s, $as in ('', ''),
                     (':disabled', '-disabled') {
      &#{$s} {
        $_url: 'assets/scale-slider#{$as}#{$asset_suffix}';

        background-image: -gtk-scaled(url('#{$_url}.png'), url('#{$_url}@2.png'));
      }
    }

    &:hover { background-color: rgba($accent, 0.10); }
    &:focus { background-color: rgba($accent, 0.12); }
    &:focus:hover { background-color: rgba($accent, 0.16); }

    &:active {
      transition: all $shorter_duration $deceleration_curve;
      background-color: rgba($accent, 0.12);
      color: rgba($accent, 0.15);
    }
  }

  // click-and-hold the slider to activate
  &.fine-tune {
    // to make the slider shrink in fine-tune mode
    slider { background-size: calc(100% - 12px); }
  }

  > marks label,
  > value { color: gtkalpha(currentColor, 0.45); }

  > marks {
    color: $track;

    @each $marks_class, $marks_pos, $marks_margin in (top, top, bottom),
                                                     (bottom, bottom, top),
                                                     (top, left, right),
                                                     (bottom, right, left) {
      &.#{$marks_class} {
        margin-#{$marks_margin}: $_marks_distance;
      }
    }
  }

  &.horizontal {
    indicator {
      min-height: $_marks_lenght;
      min-width: 1px;
    }
  }

  &.vertical {
    indicator {
      min-height: 1px;
      min-width: $_marks_lenght;
    }
  }

  // *WARNING* scale with marks madness following

  @each $dir_class, $dir_infix in ('horizontal', 'horz'),
                                  ('vertical', 'vert') {
    @each $marks_infix, $marks_class in ('marks-before', 'marks-before:not(.marks-after)'),
                                        ('marks-after', 'marks-after:not(.marks-before)') {
      &.#{$dir_class}.#{$marks_class} {
        slider {
          @each $state, $state_infix in ('', ''),
                                        (':disabled', '-disabled') {
            &#{$state} {
              $_scale_asset: 'assets/scale-#{$dir_infix}-#{$marks_infix}-slider#{$state_infix}#{$asset_suffix}';

              background-image: -gtk-scaled(url('#{$_scale_asset}.png'), url('#{$_scale_asset}@2.png'));
            }
          }
        }
      }
    }
  }

  &.color {
    min-height: 0;
    min-width: 0;

    &.horizontal {
      padding: 0 0 12px 0;

      slider {
        &:dir(ltr), &:dir(rtl) { // specificity bump
          margin-bottom: $color_slider_margin;
          margin-top: $color_marks_slider_margin;
        }
      }
    }

    &.vertical {
      &:dir(ltr) {
        padding: 0 0 0 12px;

        slider {
          margin-left: $color_slider_margin;
          margin-right: $color_marks_slider_margin;
        }
      }

      &:dir(rtl) {
        padding: 0 12px 0 0;

        slider {
          margin-right: $color_slider_margin;
          margin-left: $color_marks_slider_margin;
        }
      }
    }
  }
}

//
// Progress bars
//
progressbar {
  // sizing
  &.horizontal {
    > trough {
      min-width: 150px;
      &, > progress { min-height: $bar_size; }
    }
  }

  &.vertical {
    > trough {
      min-height: 80px;
      &, > progress { min-width: $bar_size; }
    }
  }

  // FIXME: insensitive state missing and some other state should be set probably
  color: $text-disabled;
  font-size: smaller;

  > trough { background-color: gtkalpha($primary, 0.3); border-radius: 6px; }

  > trough > progress { background-color: $primary; border-radius: 6px; }

  &.osd { // progressbar.osd used for epiphany page loading progress
    min-width: 3px;
    min-height: 3px;
    background-color: transparent;

    > trough {
      border-style: none;
      border-radius: 0;
      background-color: transparent;
      box-shadow: none;

      > progress {
        border-style: none;
        border-radius: 0;
      }
    }
  }

  > trough.empty > progress { all: unset; } // makes the progress indicator disappear, when the fraction is 0
}

//
// Level Bar
//
levelbar {
  > trough > block {
    min-width: $medium_size;
    min-height: $bar_size;
  }

  &.vertical > trough > block {
    min-width: $bar_size;
    min-height: $medium_size;
  }

  > trough {
    padding: 2px;
    border-radius: 6px;
    @include entry(normal);

    &:disabled { @include entry(disabled); }
  }

  &.horizontal.discrete block { margin: 0 1px; }
  &.vertical.discrete block { margin: 1px 0; }
  &.horizontal.discrete trough { padding: 2px 1px; }
  &.vertical.discrete trough { padding: 1px 2px; }

  > trough > block {
    &.low {
      background-color: $warning;
    }

    &.high,
    &:not(.empty) {
      background-color: $primary;
    }

    &.full {
      background-color: $success;
    }

    &.empty {
      background-color: $track;
      color: $text-disabled;
    }
  }
}

//
// Print dialog
//
window.dialog.print {
  drawing {
    color: $text;
    background: none;
    border: none;
    padding: 0;

    paper {
      background: white;
      color: #363636;
      border: 1px solid $border;
    }
  }

  .dialog-action-box { margin: 12px; }
}

//
// Frames
//
frame,
.frame {
  border: 1px solid $border;
}

frame {
  border-radius: $button_radius;

  > label {
    margin: 4px;
  }
}

actionbar > revealer >  box {
  padding: $space_size;
  border-spacing: $space_size;
  border-top: 1px solid $border;

  button:not(.suggested-action):not(.destructive-action):not(.server-list-button) { @extend %flat_button; }
}

scrolledwindow {
  // viewport.frame { // avoid double borders when viewport inside scrolled window
  //   border-style: none;
  // }

  // This is used when content is touch-dragged past boundaries.
  // draws a box on top of the content, the size changes programmatically.
  @at-root overshoot {
    &.top { @include overshoot(top); }

    &.bottom { @include overshoot(bottom); }

    &.left { @include overshoot(left); }

    &.right { @include overshoot(right); }
  }

  // Overflow indication, works similarly to the overshoot, the size if fixed tho.
  @at-root undershoot {
    &.top { @include undershoot(top); }

    &.bottom { @include undershoot(bottom); }

    &.left { @include undershoot(left); }

    &.right { @include undershoot(right); }
  }

  @at-root junction { // the small square between two scrollbars
    border-style: solid none none solid;
    border-width: 1px;
    border-color: $border;
    background-color: $base;

    &:dir(rtl) { border-style: solid solid none none; }
  }
}

//vbox and hbox separators
separator {
  min-width: 1px;
  min-height: 1px;
  background-color: $border;
}

//
// Lists
//
listview,
list {
  border-color: $border;
  background-color: $base;

  > row { padding: 2px; }
  > row.expander { padding: 0px; }
  > row.expander .row-header { padding: 2px; }
}

row {
  @at-root %row_activatable, &.activatable {
    transition: $shorter_transition;
    background-image: none;

    &:hover {
      background-color: $divider;
    }

    &.has-open-popup,
    &:active {
      background-color: $track;
    }
  }

  &:selected { @extend %selected_items; &:hover { background-color: lighten($primary, 5%); } }
}

columnview {
  // move padding to child cells
  > listview > row {
    padding: 0;

    // align horizontal sizing with header buttons
    > cell {
      padding: ($space_size + 2px) $space_size;

      &:not(:first-child) {
        border-left: 1px solid transparent;
      }
    }
  }

  // make column separators visible when :show-column-separators is true
  &.column-separators > listview > row > cell {
    border-left-color: $solid-border;
  }

  // shrink vertically for .data-table
  &.data-table > listview > row > cell {
    padding-top: 2px;
    padding-bottom: 2px;
  }
}

treeexpander {
  border-spacing: 4px;
}

columnview row:not(:selected) cell editablelabel.editing text selection {
  @extend %selected_items;
}

.rich-list { /* rich lists usually containing other widgets than just labels/text */
  & > row {
    padding: 8px 12px;
    min-height: 32px; /* should be tall even when only containing a label */

    & > box {
      border-spacing: 12px;
    }
  }
}

//
// App Notifications
//
.app-notification {
  @extend %osd;
  margin: 8px;

  button { @extend %osd_button; }

  &.frame,
  border { border-style: none; }
}

//
// Expanders
//
expander {
  transition: all $shorter_duration $standard_curve;
  min-width: 16px;
  min-height: 16px;
  -gtk-icon-source: -gtk-icontheme('pan-down-symbolic');

  &:dir(rtl) { -gtk-icon-transform: rotate(90deg); }

  color: $text-secondary;

  &:hover, &:active { color: $text; }
  &:disabled { color: $text-secondary-disabled; }

  &:selected {
    color: on($primary, secondary);

    &:hover, &:active { color: on($primary); }
    &:disabled { color: on($primary, secondary-disabled); }
  }
}

//
// Calendar
//
calendar {
  color: $text-secondary;
  border: 1px solid $border;

  > header {
    border-bottom: 1px solid $border;

    > button {
      border: none;
      box-shadow: none;
      background: none;
      border-radius: 0;
    }
    > button:backdrop {
      background: none;
    }
  }

  > grid {
    > label {
      border-radius: 3px;
    }
    > label.day-name {
    }

    > label.week-number {
    }

    > label.today {
      background-color: rgba($text, 0.15);

      &:selected {
        @extend %selected_items;
      }
    }

    > label.day-number {
      padding: 4px;

      &:selected{
        @extend %selected_items;
        border-radius: 3px;
      }
    }

    > label.day-number.other-month {
      color: gtkalpha(currentColor, 0.3);
    }
  }
}

//
// Dialogs
//
window.dialog.message { // Message Dialog styling
  &.background { background-color: $suface; }

  box.dialog-vbox.vertical {
    border-spacing: 10px;
  }

  .titlebar {
    min-height: $small_size;
    border-style: none;
    box-shadow: inset 0 1px $highlight;
    background-color: $suface;
    color: $text;

    &:backdrop { color: $text-secondary; }
  }

  .linked:not(.vertical).dialog-action-area > button {
    padding: 4px 12px;
    border-top: 1px solid $border;
    border-radius: 0;
    @extend %flat_button;

    &:first-child {
      border-bottom-left-radius: 0;
      border-top-left-radius: 0;
    }

    &:last-child {
      border-bottom-right-radius: 0;
      border-top-right-radius: 0;
    }
  }

  @each $b_type, $b_color in (suggested-action, $suggested),
                             (destructive-action, $destructive) {
    .linked:not(.vertical).dialog-action-area > button.#{$b_type} {
      color: $b_color;
      transition: $shorter_transition,
                  $shadow_transition,
                  background-size $ripple_duration $deceleration_curve,
                  background-image $ripple_opacity_duration $deceleration_curve;

      &:hover {
        color: $b_color;
        background-color: transparent;
      }

      &:active {
        transition: $shorter_transition;
        color: on($primary);
        border-color: rgba($b_color, 0.75);
        box-shadow: inset 0 0 0 9999px rgba($b_color, 0.5);
      }

      &:disabled { opacity: 0.65; }
    }
  }

  &.csd { // rounded bottom border styling for csd version
    &.background {
      // bigger radius for better antialiasing
      border-bottom-left-radius: 2px;
      border-bottom-right-radius: 2px;
    }

    .linked:not(.vertical).dialog-action-area > button {
      padding: 8px 16px;
      border-top: 1px solid $border;
      border-radius: 0;
      @extend %flat_button;

      &:first-child {
        border-bottom-left-radius: 2px;
        border-top-left-radius: 0;
      }

      &:last-child {
        border-bottom-right-radius: 2px;
        border-top-right-radius: 0;
      }
    }
  }

  entry { @extend %flat_entry; }
}

filechooser {
  .dialog-action-box { border-top: 1px solid $border; }

  #pathbarbox {
    border-bottom: 1px solid $border;
    background-color: $background;
  }
}

filechooserbutton>button>box {
  border-spacing: $space_size;
}

filechooserbutton:drop(active) {
  box-shadow: none;
  border-color: transparent;
}

//
// Sidebar
//
.sidebar {
  border-style: none;
  background-color: $suface;

  @at-root %sidebar_left,
  &:dir(ltr),
  &.left,
  &.left:dir(rtl) {
    border-right: 1px solid $border;
    border-left-style: none;
  }

  @at-root %sidebar_right
  &:dir(rtl),
  &.right {
    border-left: 1px solid $border;
    border-right-style: none;
  }

  listview.view,
  list { background-color: transparent; }
  row { transition: none; }

  separator,
  .separator {
    min-height: 0;
    border-color: transparent;
    background-color: transparent;
  }

  paned & { &.left, &.right, &.left:dir(rtl), &:dir(rtl), &:dir(ltr), & { border-style: none; }}
}

stacksidebar {
  list.separators:not(.horizontal) > row:not(.separator) {
    border-bottom: none;
  }

  row {
    padding: $space_size * 2 $space_size;
    transition: none;

    > label {
      padding-left: $space_size;
      padding-right: $space_size;
    }

    &.needs-attention > label { @extend %needs_attention; }
  }
}

separator.sidebar {
  background-color: $border;
}

//
// Navigation Sidebar
//
.navigation-sidebar {
  padding: $space_size 0; //only vertical padding. horizontal row size would clip

  > separator {
    margin: $space_size;
  }

  > row {
    min-height: ($space_size + 10px) * 2;
    padding: 0 $space_size;
    border-radius: $button_radius;
    margin: 0 $space_size 2px;

    &:hover,
    &:focus-visible:focus-within {
      color: $text;
      background-color: rgba($text, 0.06);
    }

    &:selected {
      color: $text;
      background-color: rgba($text, 0.08);

      label { color: $text; }

      &:hover {
        background-color: rgba($text, 0.12);
      }

      &:focus-visible:focus-within {
        outline-width: 0;
        color: on($primary);
        background-color: $primary;
        &:hover { background-color: lighten($primary, 10%); }
      }
    }

    &:disabled { color: $text-secondary-disabled; }
  }
}

//
// File chooser
//
placessidebar {
  > viewport.frame { border-style: none; }

  list { padding: (4px - 3px) 0 4px; }

  .navigation-sidebar > row {
    // Needs overriding of the GtkListBoxRow padding
    min-height: $space_size * 5;
    margin: -1px 0; // Remove unknown margins
    padding: 0;

    // Using margins/padding directly in the SidebarRow
    // will make the animation of the new bookmark row jump
    > revealer { padding: 0 12px; }

    &:selected {
      color: on($primary);

      button.sidebar-button {
        color: on($primary, secondary);

        &:hover, &:active, &:checked {
          background-color: $track;
          color: on($primary);
        }

        &:disabled { color: on($primary, secondary-disabled); }

        &:checked:disabled {
          background-color: rgba(white, 0.12);
          color: on($primary, disabled);
        }
      }
    }

    &:disabled { color: $text-disabled; }

    image.sidebar-icon {
      opacity: 0.45; // dim the device icons

      &:dir(ltr) { padding-right: $space_size + 2px; }
      &:dir(rtl) { padding-left: $space_size + 2px; }
    }

    label.sidebar-label {
      &:dir(ltr) { padding-right: 2px; }
      &:dir(rtl) { padding-left: 2px; }
    }

    button.sidebar-button {
      @extend %simple_flat_button;
      @extend %small_button;
    }

    &.sidebar-placeholder-row {
      min-height: 2px;
      padding: 0 8px;
      background-image: image($accent);
      background-clip: content-box;
    }

    &.sidebar-new-bookmark-row { color: $accent; }

    &:drop(active):not(:disabled) {
      box-shadow: inset 0 0 0 2px $accent;
    }
  }
}

placesview {
  .server-list-button > image { -gtk-icon-transform: rotate(0turn); }
  .server-list-button:checked > image { -gtk-icon-transform: rotate(-0.5turn); }

  // this selects the "connect to server" label
  > actionbar > revealer > box > label {
    padding-left: $space_size + 2px;
    padding-right: $space_size + 2px;
  }

  > actionbar > revealer > box > box {
    border-spacing: $space_size;
  }
}


//
// Paned
//
paned {
  > separator {
    min-width: 1px;
    min-height: 1px;
    -gtk-icon-source: none; // defeats the ugly default handle decoration
    border-style: none; // just to be sure
    background-color: transparent;
    // workaround, using background istead of a border since the border will get rendered twice (?)
    background-image: image($solid-border);
    background-size: 1px 1px;

    &.wide {
      min-width: 6px;
      min-height: 6px;
      background-color: $background;
      background-image: image($solid-border), image($solid-border);
      background-size: 1px 1px, 1px 1px;
    }
  }

  &.horizontal > separator {
    background-repeat: repeat-y;

    &:dir(ltr) {
      margin: 0 -8px 0 0;
      padding: 0 8px 0 0;
      background-position: left;
    }

    &:dir(rtl) {
      margin: 0 0 0 -8px;
      padding: 0 0 0 8px;
      background-position: right;
    }

    &.wide {
      margin: 0;
      padding: 0;
      background-repeat: repeat-y, repeat-y;
      background-position: left, right;
    }
  }

  &.vertical > separator {
    margin: 0 0 -8px 0;
    padding: 0 0 8px 0;
    background-repeat: repeat-x;
    background-position: top;

    &.wide {
      margin: 0;
      padding: 0;
      background-repeat: repeat-x, repeat-x;
      background-position: bottom, top;
    }
  }
}

//
//  GtkVideo
//

video {
  & image.osd {
    min-width: 64px;
    min-height: 64px;
    border-radius: $circular_radius;
  }
  background: black;
}

//
// GtkInfoBar
//
infobar {
  border-style: none;

  > revealer > box {
    padding: $space_size + 2px;
    border-spacing: $space_size * 2;
  }

  &.info > revealer > box { background-color: $info; }
  &.question > revealer > box { background-color: $question; }
  &.warning > revealer > box { background-color: $warning; }
  &.error > revealer > box { background-color: $error; }

  &.info,
  &.question,
  &.warning,
  &.error {
    > label, & { color: on($primary); }

    button { @extend %selected_button; }
    link { color: on($primary); }
  }
}

// Buttons on selected backgrounds
%selected_button {
  & {
    color: on(dark);
    background-color: transparentize(on(dark), 1);
    border: 1px solid transparentize(on(dark), 0.5);
    box-shadow: none;
  }
  &.flat {
    color: on(dark);
    background-color: transparentize(on(dark), 1);
    box-shadow: none;
    &:disabled {
      &, label { color: transparentize(on(dark), 0.6); }
      box-shadow: none;
    }
  }
  &:hover {
    color: on(dark);
    background-color: transparentize(on(dark), 0.8);
    border-color: transparentize(on(dark), 0.2);
    box-shadow: none;
  }
  &:active, &:active:hover, &:checked {
    color: on(dark);
    background-color: transparentize(on(dark), 0.9);
    border-color: transparentize(on(dark), 0.2);
    box-shadow: none;
  }
  &:disabled {
    &, label { color: transparentize(on(dark), 0.5); }
    background-color: transparentize(on(dark), 1);
    border-color: transparentize(on(dark), 0.6);
    box-shadow: none;
    &:active, &:checked {
      color: on(dark);
      background-color: transparentize(on(dark), 0.5);
      border-color: transparentize(on(dark), 0.6);
      box-shadow: none;
    }
  }
}

//
// Tooltips
//
tooltip {
  &.background {
    // background-color needs to be set this way otherwise it gets drawn twice
    // see https://bugzilla.gnome.org/show_bug.cgi?id=736155 for details.
    box-shadow: inset 0 1px $highlight;
    background-color: gtkalpha($base, 0.9);
  }

  padding: $space_size ($space_size + 4px);
  border-radius: 3px;
  box-shadow: none; // otherwise it gets inherited by windowframe.csd

  &:not(.csd) {
    border: 1px solid $border;
    border-radius: 3px;
    background-clip: $extra_background_clip;
  }

  label {
    // tooltip label has already 6px margins
    min-height: 20px;
    padding: 0 2px;
  }

  > box {
    border-spacing: $space_size;
  }
}

//
// Color Chooser
//
colorswatch {
  // This widget is made of two boxes one on top of the other, the lower box is colorswatch {} the other one
  // is colorswatch overlay {}, colorswatch has the programmatically set background, so most of the style is
  // applied to the overlay box.

  // base color corners rounding
  // to avoid the artifacts caused by rounded corner anti-aliasing the base color
  // sports a bigger radius.
  // nth-child is needed by the custom color strip.

  &.top {
    border-top-left-radius: $button_radius + 0.5px;
    border-top-right-radius: $button_radius + 0.5px;

    overlay {
      border-top-left-radius: $button_radius;
      border-top-right-radius: $button_radius;
    }
  }

  &.bottom {
    border-bottom-left-radius: $button_radius + 0.5px;
    border-bottom-right-radius: $button_radius + 0.5px;

    overlay {
      border-bottom-left-radius: $button_radius;
      border-bottom-right-radius: $button_radius;
    }
  }

  &.left,
  &:first-child:not(.top) {
    border-top-left-radius: $button_radius + 0.5px;
    border-bottom-left-radius: $button_radius + 0.5px;

    overlay {
      border-top-left-radius: $button_radius;
      border-bottom-left-radius: $button_radius;
    }
  }

  &.right,
  &:last-child:not(.bottom) {
    border-top-right-radius: $button_radius + 0.5px;
    border-bottom-right-radius: $button_radius + 0.5px;

    overlay {
      border-top-right-radius: $button_radius;
      border-bottom-right-radius: $button_radius;
    }
  }

  &.dark overlay { color: on(dark); }
  &.light overlay { color: on(dark); }
  &.dark { color: on(dark); } // for focus ring
  &.light { color: on(dark); } // for focus ring

  &:drop(active) {
    box-shadow: none;

    &.light overlay {
      box-shadow: $shadow_1, 0 0 0 2px $accent;
    }

    &.dark overlay {
      box-shadow: $shadow_1, 0 0 0 2px $accent;
    }
  }

  overlay {
    transition: $shadow_transition;
    box-shadow: $shadow_1;

    &:hover { box-shadow: $shadow_2; }
  }

  &#add-color-button {
    border-radius: $button_radius $button_radius 0 0;
    color: on(dark); // for focus ring

    &:only-child { border-radius: $button_radius; }

    overlay {
      background-image: linear-gradient(to right,
                                        $error 25%,
                                        $warning 25%, $warning 50%,
                                        $info 50%, $info 75%,
                                        $question 75%);
      color: on(dark);
    }
  }

  &:disabled {
    opacity: 0.3;

    overlay { box-shadow: none; }
  }

  row:selected & {
  }

  &#editor-color-sample {
    border-radius: $button_radius + 0.5px;

    overlay { border-radius: $button_radius; }

    // overlay:hover { box-shadow: $shadow_1; }
  }
}

// colorscale popup
colorchooser .popover.osd {
  transition: $shadow_transition;
  border-radius: 2px;
  box-shadow: $shadow_2, inset 0 1px $highlight;
  background-color: $base;

  &:backdrop { box-shadow: $shadow_1, inset 0 1px $highlight; }

  // spinbutton:not(.vertical) { @extend %flat_entry; }
}

//
// Misc
//
//content view (grid/list)
.content-view {
  background-color: $background;

  &:hover { -gtk-icon-filter: brightness(1.2); }

  .tile {
    margin: 2px;
    background-color: if($variant=='light', transparent, black);
    border-radius: 0;
    padding: 0;

    &:active, &:selected { background-color: if($variant=='light', transparent, $primary); }
    &:disabled { background-color: if($variant=='light', transparent, $text-disabled); }
  }

  > rubberband { @extend rubberband; }
}

.scale-popup {
  .osd & > contents,
  .osd & > arrow {
    @extend %osd;
    margin: 0;
  }

  .osd & button.flat {  //FIXME: quick hack, redo properly
  }

  button { // +/- buttons on GtkVolumeButton popup
  }
}

//
// Window Decorations
//
window {
  border: none;

  &.csd {
    transition: $shadow_transition;
    border-radius: $window_radius $window_radius 0 0;
    box-shadow: $shadow_5, 0 16px 16px 2px rgba(black, 0), 0 6px 18px 5px rgba(black, 0);
    margin: 0;

    &:backdrop {
      box-shadow: $shadow_4, 0 16px 16px 2px rgba(black, 0), 0 6px 18px 5px rgba(black, 0);
    }

    &.popup {
      border-radius: $menu_radius;
      box-shadow: $shadow_4;
    }

    &.dialog.message {
      border-radius: $window_radius;
      box-shadow: $shadow_4;
    }

    &.solid-csd {
      margin: 0;
      padding: 1px 2px 2px;
      border: 1px solid if($topbar == 'light', darken($header, 18%), darken($header, 10%));
      border-radius: 0;
      box-shadow: inset 0 0 0 2px $header, inset 0 1px $highlight;
      background-color: $solid-border;
    }
  }

  &.maximized,
  &.fullscreen,
  &.tiled,
  &.tiled-top,
  &.tiled-left,
  &.tiled-right,
  &.tiled-bottom { border-radius: 0; }

  &.popup { box-shadow: none; }

  .ssd & { box-shadow: 0 0 0 1px rgba(black, 0.16); } //just doing borders, wm draws actual shadows
}

// catch all extend :)
%selected_items {
  background-color: $primary;
  color: on($primary);

  &:disabled { color: on($primary, disabled); }
}

.monospace { font-family: monospace; }

//
// Title buttons
//

%windows_button {
  margin: 0 $space_size/2;
  padding: 0;
  min-width: 26px;
  min-height: 26px;
  animation: none;
  box-shadow: none;
  border: none;
  color: transparent;
  background-color: transparent;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 16px 16px;

  &:hover, &:active, &:checked {
    box-shadow: none;
    border: none;
    color: transparent;
    animation: none;
    transition: background-size $shorter_duration $deceleration_curve;
    background-color: transparent;
    background-size: 22px 22px;
  }

  &:backdrop {
    opacity: 1;
    color: transparent;
  }
}

%titlebuttons {
  windowcontrols button {
    &:hover { @include button(header-hover); }
    &:active, &:checked { @include button(header-active); }

    &.close, &.maximize, &.minimize { @extend %windows_button; }

    // Load png assets for each button
    @each $k in ('close', 'maximize', 'minimize') {
      @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {

        &.#{$k}#{$l} { background-image: -gtk-scaled(url('assets/window-assets/titlebutton-#{$k}#{$m}#{$darker_asset_suffix}.png'),
                                                     url('assets/window-assets/titlebutton-#{$k}#{$m}#{$darker_asset_suffix}@2.png')); }
      }
    }
  }

  .fullscreen &,
  .maximized & {
    windowcontrols button {
      @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {
      &.maximize#{$l} { background-image: -gtk-scaled(url('assets/window-assets/titlebutton-restore#{$m}#{$darker_asset_suffix}.png'),
                                                      url('assets/window-assets/titlebutton-restore#{$m}#{$darker_asset_suffix}@2.png')); }
      }
    }
  }
}

headerbar,
.titlebar {
  &, .csd &, .solid-csd &,
  &.default-decoration,
  .csd &.default-decoration {  // needed under wayland, since all gtk3 windows are csd windows
    @if $titlebutton == 'default' {
      @extend %titlebuttons;
    } @else {
      button.titlebutton.close {
        border-radius: $button_radius;
      }
    }
  }
}

%solid_titlebuttons {
  .csd &, .solid-csd & {
    windowcontrols button {
      &.close, &.maximize, &.minimize { @extend %windows_button; }

      // Load png assets for each button
      @each $k in ('close', 'maximize', 'minimize') {
        @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {

        &.#{$k}#{$l} { background-image: -gtk-scaled(url('assets/window-assets/titlebutton-#{$k}#{$m}#{$darker_asset_suffix}.png'),
                                                     url('assets/window-assets/titlebutton-#{$k}#{$m}#{$darker_asset_suffix}@2.png')); }
        }
      }
    }
  }

  .csd.maximized &, .solid-csd.maximized & {
    button.titlebutton {
      @each $l, $m in ('',''), (':backdrop','-backdrop'), (':hover','-hover'), (':active','-active') {
      &.maximize#{$l} { background-image: -gtk-scaled(url('assets/window-assets/titlebutton-restore#{$m}#{$darker_asset_suffix}.png'),
                                                      url('assets/window-assets/titlebutton-restore#{$m}#{$darker_asset_suffix}@2.png')); }
      }
    }
  }
}

// solid-csd Window manager buttons
@if $titlebutton == 'default' {
  headerbar:not(.default-decoration) { @extend %solid_titlebuttons; }
}

//
// Touch Copy & Paste
//
//touch selection handlebars for the Popover.osd above
cursor-handle {
  border-radius: $circular_radius;
  background-color: $accent;
  background-image: none;

  &.top:dir(ltr), &.bottom:dir(rtl) {
    padding-left: $space_size;
    border-top-right-radius: 0;
  }

  &.bottom:dir(ltr), &.top:dir(rtl) {
    padding-right: $space_size;
    border-top-left-radius: 0;
  }

  &.insertion-cursor:dir(ltr), &.insertion-cursor:dir(rtl) {
    $_url: 'assets/slider-horz-scale-has-marks-above#{$asset_suffix}';
    -gtk-icon-source: -gtk-scaled(url('#{$_url}.png'),
                                  url('#{$_url}@2.png'));
  }
}

shortcuts-section {
  margin: 20px;
}

.shortcuts-search-results {
  margin: 20px;
  border-spacing: 24px;
}

.context-menu { font: initial; } // Decouple the font of context menus from their entry/textview

%circular_button,
button.circular { // FIXME: aggregate to buttons
  border-radius: 100px;

  // label { padding: 0; }
}

button.circular { row & { margin: 0 5px; } } // Make the circular button hover shadow on row fully displayed

%small_button {
  min-height: $small_size;
  min-width: $small_size;
  padding: 0;
  border-radius: $circular_radius;
}

// shortcut window keys
shortcut > .keycap {
  min-width: 28px - 8px * 2;
  min-height: 28px - 2px;
  margin-top: 2px;
  padding-bottom: 2px;
  padding-left: 8px;
  padding-right: 8px;

  border: solid 1px $border;
  border-radius: 2px + 1px;
  box-shadow: inset 0 -2px $border;
  background-color: $base;
  color: $text;
  font-size: smaller;
}

:not(decoration):not(window):drop(active) { // FIXME needs to be done widget by widget, this wildcard should really die
  transition: $shorter_transition;
  box-shadow: $shadow_1, inset 0 0 0 2px $accent;
  caret-color: $accent;
}

stackswitcher button.text-button { min-width: 100px; } // FIXME aggregate with buttons

stackswitcher button.circular,
stackswitcher button.text-button.circular { // FIXME aggregate with buttons
  min-width: $medium_size;
  min-height: $medium_size;
  border-radius: 100px;
  padding: 0;
}

//
// App Icons
//
.lowres-icon {
    -gtk-icon-shadow: 0 -1px rgba(0,0,0,0.05),
      1px 0 rgba(0,0,0,0.1),
      0 1px rgba(0,0,0,0.3),
      -1px 0 rgba(0,0,0,0.1);
}

.icon-dropshadow {
  -gtk-icon-shadow: 0 1px 12px rgba(0,0,0,0.05),
      0 -1px rgba(0,0,0,0.05),
      1px 0 rgba(0,0,0,0.1),
      0 1px rgba(0,0,0,0.3),
      -1px 0 rgba(0,0,0,0.1);
}

//
// Emoji
//
popover.emoji-picker {
  > contents {
    padding: 0;
  }
}

.emoji-searchbar {
  padding: $space_size;
  border-spacing: $space_size;
  border-bottom: 1px solid $border;
}

.emoji-toolbar {
  padding: $space_size;
  border-spacing: $space_size;
  border-top: 1px solid $border;
}


// mimic tab style
button.emoji-section {
  margin-top: -1px;
  padding: 0 8px;
  min-width: 24px;
  min-height: $medium_size;
  border-radius: 0;
  box-shadow: none;

  &:hover { box-shadow: inset 0 2px $track; }

  &:active {
    box-shadow: inset 0 2px $primary;
  }

  &:checked {
    box-shadow: inset 0 2px $primary;
    background-color: transparent;
  }

  &:first-child { margin-left: 4px; }
  &:last-child { margin-right: 4px; }
}

popover.emoji-picker emoji {
  font-size: x-large;
  padding: $space_size;
  border-radius: $space_size;

  &:focus,
  &:hover {
    background: $primary;
  }
}

emoji-completion-row > box {
  border-spacing: $space_size;
  padding: 2px $space_size;
}

emoji-completion-row:focus,
emoji-completion-row:hover {
  @extend %selected_items;
}

emoji-completion-row emoji:focus,
emoji-completion-row emoji:hover {
  background: none;
  box-shadow: inset 0 0 0 2px rgba($text, 0.05);
  border-radius: 3px;
}

popover.entry-completion > contents {
  padding: 0;
}

statusbar {
  padding: $space_size ($space_size + 4px);
}
